<?php
declare(strict_types=1);
namespace Dao;
// hook dao_sys_album_attach_use.php

use Model\SysAlbumAttachModel;
use Swoole\Timer;

class SysAlbumAttachDao extends SysAlbumAttachModel
{
	// hook dao_sys_album_attach_public_start.php

	protected array $add_rule	=	[];
    protected array $edit_rule	=	[];

    protected array $rule	=	[
		/*
		"mobile"=>[
			"max"=>3
			"min"=>3
			"func"=>'isMobile'
			"error"=>false,
			'message'=>'格式有误'
		],
		"username"=>[
			"max"=>3
			"min"=>3
			"func"=>'checkS'
			"error"=>false,
			'message'=>'格式有误'
		],
		*/
	];
	//数据，字段，验证规则
	/*
	function isMobile($data,$field,$val){
	
		return true;
	}
	*/
	
	// hook dao_sys_album_attach_public_end.php

    public function auto_load()
    {
        // hook model_user_auto_load_start.php
        //$this->add_with($this->UserAssets->table, 'uid', 'uid', '*');
        if ($this->http_server->worker_id == 0) {
            Timer::after(1000, function () {
                $this->reload();
            });
        }
    }

    public function reload($cond=[])
    {
        $attachs = $this->select($cond);
        if (!empty($attachs)) {
            foreach ($attachs as $v) {
               $this->T_SysAlbumAttach->set($v['AttachID'].'', ['Patch'=>$v['Patch']]);
            }
        }
    }

    public function GetPatchByID(int $AttachID)
    {
        $Patch = $this->T_SysAlbumAttach->get($AttachID.'', 'Patch');
        return !empty($Patch) ? _CONF('OssHost') .'/'.$Patch : _CONF('OssHost') .'/static/image/NoImage.png';
    }
	// hook dao_sys_album_attach_end.php
}
?>